##########################################################
# These are for mingw32/gcc - Minimalist GNU Win32
# See
# o GCC homepage
#   http://www.gnu.org/software/gcc
# o GCC compilations flags
#   http://www.gnu.org/software/gcc/onlinedocs/gcc_2.html
# o Minimalist GNU Win32
#   http://www.xraylith.wisc.edu/~khan/software/gnu-win32/gcc.html
#   ftp://ftp.xraylith.wisc.edu/pub/khan/gnu-win32/mingw32/gcc-2.95
#   http://www.geocities.com/Tokyo/Towers/6162/gcc.html
##########################################################

ifeq ($(SMALLCODE), 1)
C_OPT = -Os
else
C_OPT = -O3
endif

CDEFINES =					\
	-DWIN32					\
	-D_NO_COM				\
	-D_WIN32				\
	-D_XLOCNUM_				\
	-D__HTMLHELP_H__			\
	-DCINTERFACE				\
	-U_NO_COM				\
	-UNONAMELESSUNION

CWARNINGS =					\
    -Wall					\
    -W						\
    -Wcast-align				\
    -Wcast-qual					\
    -Wchar-subscripts				\
    -Wcomment					\
    -Wformat					\
    -Wimplicit					\
    -Wimplicit-function-declaration		\
    -Wimplicit-int				\
    -Winline					\
    -Wlong-long					\
    -Wmain					\
    -Wmissing-declarations			\
    -Wmissing-noreturn				\
    -Wmissing-prototypes			\
    -Wmultichar					\
    -Wnested-externs				\
    -Wparentheses				\
    -Wpointer-arith				\
    -Wreturn-type				\
    -Wsign-compare				\
    -Wswitch					\
    -Wtrigraphs					\
    -Wundef					\
    -Wuninitialized				\
    -Wunknown-pragmas				\
    -Wunused					\
    -Wwrite-strings

#    -Wstrict-prototypes			\
#    -Waggregate-return				\
#    -ansi					\
#    -pedantic					\
#    -Wredundant-decls				\
#    -Wbad-function-cast			\
#    -Wid-clash-32				\
#    -Wconversion				\
#    -Werror					\
#    -Wlarger-than-len				\
#    -Wtraditional				\
#    -Wshadow

ifeq ($(COPTIMIZE), 1)
CFLAGS += $(CWARNINGS) $(C_OPT) $(CDEFINES) -DNDEBUG -U_DEBUG
else
# CFLAGS += -Wall -O0
# gcc requires the generation of a dependency tree,
# and hence at least -O1,
# to detect any use of uninitialized variables
CFLAGS +=  $(CWARNINGS) -O1 $(CDEFINES) -UNDEBUG -U_DEBUG # -D_DEBUG
endif

ifeq ($(CDEBUG), 1)
CFLAGS += -g
endif

# These seem to be platform specific, not compiler specific

ifeq ($(NOASM), 1)
CFLAGS += -DNOASM
endif

ifeq ("$(CPU)", "")
CPU=pentiumpro
endif

CFLAGS +=					\
	-c -mcpu=$(CPU) -mno-cygwin		\
	-DVC_EXTRALEAN				\
	-DWIN32_EXTRA_LEAN			\
	-DWIN32_LEAN_AND_MEAN			\
	-D__CYGWIN__				\
	-I/usr/include/mingw			\
	-I/usr/include/w32api			\
        -I$(BASEDIR)/misc/mssdk/include		\
	-I$(DXSDK)/include

# -Id:/Program\ Files/Microsoft\ Visual\ Studio/VC98/Include	
# -Ic:/Program\ Files/Microsoft\ Visual\ Studio/VC98/Include	
# -Id:/Program\ Files/Microsoft\ Visual\ Studio/VC98/MFC/Include	
# -Ic:/Program\ Files/Microsoft\ Visual\ Studio/VC98/MFC/Include	
# -Id:/Program\ Files/HTML\ Help\ Workshop/include		
# -Ic:/Program\ Files/HTML\ Help\ Workshop/include

CFLAGS += -fno-rtti -fno-exceptions

ifeq ("$(COMPILER)", "")
COMPILER=cc
endif

ifeq ("$(LINKER)", "")
# It should be this, but we have a rather strange idea of LINKER
LINKER=gcc
endif

ifeq ("$(MSVCDIR)", "")
MSVCDIR='c:/Program Files/Microsoft Visual Studio/VC98'
endif

ifeq ("$(DXSDK)", "")
DXSDK='d:/mssdk'
endif

CC        = gcc
CPP       = $(CC)
COUT      = -c -o
LOUT      = -e
SOUT      = -S -o $@
CPPOPT    = -E -P

LD        = gcc
LOUT      = -o

ifeq  ("$(RWTARGET)", "d3d8")
LFLAGS += \
$(DXSDK)/lib/d3d8.$(L) 

# $(DXSDK)/lib/DSETUP.$(L) \
# $(DXSDK)/lib/amstrmid.$(L) \
# $(DXSDK)/lib/d3dx.$(L) \
# $(DXSDK)/lib/d3dx8.$(L) \
# $(DXSDK)/lib/d3dx8d.$(L) \
# $(DXSDK)/lib/d3dx8dt.$(L) \
# $(DXSDK)/lib/d3dxd.$(L) \
# $(DXSDK)/lib/d3dxof.$(L) \
# $(DXSDK)/lib/ddraw.$(L) \
# $(DXSDK)/lib/dinput.$(L) \
# $(DXSDK)/lib/dinput8.$(L) \
# $(DXSDK)/lib/dmoguids.$(L) \
# $(DXSDK)/lib/dplayx.$(L) \
# $(DXSDK)/lib/dpnaddr.$(L) \
# $(DXSDK)/lib/dpnet.$(L) \
# $(DXSDK)/lib/dpnlobby.$(L) \
# $(DXSDK)/lib/dpvoice.$(L) \
# $(DXSDK)/lib/dsound.$(L) \
# $(DXSDK)/lib/dxerr8.$(L) \
# $(DXSDK)/lib/dxguid.$(L) \
# $(DXSDK)/lib/dxtrans.$(L) \
# $(DXSDK)/lib/ksproxy.$(L) \
# $(DXSDK)/lib/ksuser.$(L) \
# $(DXSDK)/lib/msdmo.$(L) \
# $(DXSDK)/lib/qedit.$(L) \
# $(DXSDK)/lib/quartz.$(L) \
# $(DXSDK)/lib/strmiids.$(L) 

endif

ifeq  ("$(RWTARGET)", "d3d7")
LFLAGS += \
$(DXSDK)/lib/dxguid.$(L) \
$(DXSDK)/lib/d3dim.$(L) \
$(DXSDK)/lib/ddraw.$(L) \
$(DXSDK)/lib/dinput.$(L) 
endif

ifeq  ("$(RWTARGET)", "opengl")
LFLAGS += -lopengl32
endif

LFLAGS += \
-lkernel32 \
-luser32 \
-lgdi32 \
-lshell32 \
-lwinmm \
-lm 

# -lcrtdll

ifeq ($(CDEBUG), 1)
LFLAGS += -g
endif

AS        = ml
ASFLAGS   = -I$(SRCDIR) -I$(DEVDIR)/$(RWTARGET) -c -W2 -Cp -Zm -DFUNCSTD -DBCC -DSTACK -coff
AOUT      = -nologo -Fo

# Librarian options (for append, we include the source lib again)
AR		= ar -r
ARCREATEFLAGS   = $@ $^
ARAPPENDFLAGS	= -out:$@ $@

# How to run programs (no need for shell/simulator)
RUNIT		=

# We do want assembler
NOASM = 1

%.res : %.rc
	windres \
	 --include-dir c:/MFC/Include \
	-O coff -i $^ -o $@

# --include-dir c:/Program\ Files/Microsoft\ Visual\ Studio/VC98/MFC/Include 

# Directory creation
ifndef MD
MD = mkdir -p
endif

# Patch support
ifeq ($(RWPATCH), 1)
RWLIBS +=					\
	$(RWLIBDIR)/$(LP)rppatch.$(L)			\
	$(RWLIBDIR)/$(LP)rtbezpat.$(L)
endif # ($(RWPATCH), 1)

CPPFLAGS += $(CFLAGS)

